home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_7 / issue_07 / basicforum / heaptest2 (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1994-02-05  |  3.2 KB  |  160 lines

  1.  >HeapTest 
  2.  Squished by Lofty's !Shrink vsn 3.01 on 05-Feb-94 
  3. _heap_init   
  4. quit%   = 
  5. a%      = 0
  6. b%      = 0
  7. blk%    = 0
  8. amount$ = ""
  9. g       = 0
  10.  '"Slot size currently ";~_SlotSize%
  11.  "Select from..."                     
  12.  "1= fetch"'"2= return"'"3= resize"'"4= quit"
  13.   g = 
  14.  - 48
  15.        
  16.  "size to fetch: &"a$
  17.       
  18.  a$ <> "" 
  19.         a%   = 
  20. ("&" + a$)
  21. !        blk% = 
  22. _heap_get(a%)
  23.         
  24.  blk% > 0 
  25. 0          
  26.  '"Block allocated at &" + 
  27. ~blk%
  28.         
  29. 0          
  30.  '"Unable to claim enough memory"
  31.         
  32.       
  33. "      
  34.  "block to return: &"a$
  35.       
  36.  a$ <> "" 
  37.         a% = 
  38. ("&" + a$)
  39.         b% = a%
  40.         
  41. _heap_release(a%)
  42.         
  43.  (a% = 0) 
  44. $;          
  45.  '"Block at &" + 
  46. ~b% + " has been released"
  47.         
  48. &,          
  49.  '"No block exists at &"+
  50.         
  51.       
  52. *"      
  53.  "Block to resize: &"a$
  54. +0      
  55.  "Amount (-ve to decrease): &"amount$
  56.       
  57.  a$ <> "" 
  58.         a% = 
  59. ("&" + a$)
  60.         b% = a%
  61. /(        
  62. _heap_resize(a%,
  63. (amount$))
  64.         
  65.  (a% > 0) 
  66. 1<          
  67.  '"Block at &" + 
  68. ~b% + " has been resized ";
  69. 25          
  70.  a% <> b% 
  71.  "(now at &"+
  72. ~a%+")" 
  73.         
  74. 48          
  75.  a% = -3 
  76.  '"No block exists at &"+
  77. 5<          
  78.  a% = -2 
  79.  '"Unable to claim enough memory"
  80. 6>          
  81.  a% = -1 
  82.  '"Block size is now 0 or negative"
  83.         
  84.       
  85.       quit% = 
  86.  quit%
  87. _heap_init
  88. _Heap% = 
  89.  "OS_ReadMemMapInfo" 
  90.  _PageSize%
  91. _SlotSize% = _Heap% - &8000
  92.  "Wimp_SlotSize",_SlotSize% + _PageSize%,-1 
  93.  _SlotSize%
  94. D"_HeapEnd% = _SlotSize% + &8000
  95.  _HeapEnd% <= _Heap% 
  96.  0,"Can't claim space for heap"
  97.  "OS_Heap",0,_Heap%,,_HeapEnd% - _Heap%
  98. _heap_get(size%)
  99.  maxfree%,nrpages%,oldheapend%,ptr%
  100.  "OS_Heap",1,_Heap% 
  101.  ,,maxfree%
  102.  size% > maxfree% 
  103. M,  nrpages% = 1 + (size% 
  104.  _PageSize%) : 
  105.  "Wimp_SlotSize",_SlotSize% + nrpages% * _PageSize%,-1 
  106.  _SlotSize%
  107.   oldheapend% = _HeapEnd%
  108. P&  _HeapEnd%   = _SlotSize% + &8000
  109.  "OS_Heap",5,_Heap%,,_HeapEnd% - oldheapend%
  110.  "OS_Heap",1,_Heap% 
  111.  ,,maxfree% : 
  112.  size% > maxfree% 
  113.   ptr% = -1
  114.  "OS_Heap",2,_Heap%,,size% 
  115.  ,,ptr%
  116. = ptr%
  117. _heap_release(
  118.  ptr%)
  119.  maxfree%,nrpages%,flg%
  120.  "XOS_Heap",3,_Heap%,ptr% 
  121.  ;flg%     
  122.  (flg% 
  123.  1) = 0 
  124.  "OS_Heap",1,_Heap% 
  125.  ,,maxfree% 
  126.  maxfree% > _PageSize% 
  127.     nrpages% = 0 : 
  128. b        
  129. c5      
  130.  "XOS_Heap",5,_Heap%,,-_PageSize% 
  131.  ;flg%
  132.       
  133.  (flg% 
  134.  1) = 0 
  135.         nrpages% += 1
  136.       
  137.  (flg% 
  138.  1) <> 0
  139.  nrpages% > 0 
  140. iO      
  141.  "Wimp_SlotSize",_SlotSize% - nrpages% * _PageSize%,-1 
  142.  _SlotSize%
  143. j(      _HeapEnd% = _SlotSize% + &8000
  144. k        
  145. l?    
  146.  "OS_Heap",5,_Heap%,,(_HeapEnd% - _Heap%) - _Heap%!12
  147.   ptr% = 0
  148.   ptr% = -1
  149. _heap_resize(
  150.  ptr%,change%)
  151.  flg%
  152.  "XOS_Heap",6,_Heap%,ptr% 
  153.  ;flg% 
  154.  (flg% 
  155.   ptr% = -3
  156.  "XOS_Heap",4,_Heap%,ptr%,change% 
  157.  ,,ptr%;flg%
  158.  (flg% 
  159.  ptr% = -2
  160.